package com.umiwe.permission.controller;


import com.umiwe.entity.User;
import com.umiwe.permission.mapper.UserMapper;
import com.umiwe.permission.service.UserService;
import com.umiwe.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;


@RestController
public class TestController {

    @Autowired
    private UserService userService;

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/product/{id}")
    public User index(@PathVariable("id") Long id) {
        User user= new User();
        user.setHello("H记得请我吃饭啊 id:"+id);
        user.setId(1);
        return user;
    }

    @RequestMapping("/feign/index")
    public String index(@RequestBody String name) {
        return "你好啊="+name;
    }

    @GetMapping(value = "/test2/{id}")
    private String test(@PathVariable("id") Long id) {
        return "PathVariable : " + id + " password : " + 123456;
    }

    @GetMapping(value = "/test4/{string}")
    private String test2(@PathVariable("string") String string) {
        return "PathVariable : " + string + " password : " + 123456;
    }

    /**
     * liximing
     * @param userName
     * @param userId
     * @return
     */
    @PostMapping("/get/token")
    public Result getToken(String userName, String userId){
        List list = new LinkedList();
        return Result.error(ResultCode.PARAM_IS_INVALID);
    }

    /**
     * liximign
     * @param token
     * @return
     */
    @GetMapping("/token")
    public boolean token(String token){
        Object o = redisUtil.get("1");
        redisUtil.set("1", "123", 10L, TimeUnit.SECONDS);
        redisUtil.set("2", "123", 10L, TimeUnit.SECONDS);
        redisUtil.set("3", "123", 10L, TimeUnit.SECONDS);
        redisUtil.set("4", "123", 10L, TimeUnit.SECONDS);
        redisUtil.set("5", "123", 10L, TimeUnit.SECONDS);
        return redisUtil.set("1", "123", 10L, TimeUnit.SECONDS);
    }

    /**
     * lixming
     * @param unionid
     * @return
     */
    @PostMapping("/user/unionid")
    public Result getUnionid(String unionid){
        return userService.getUserId(unionid);
    }

    /**
     * 测试 redis
     * liximng
     */
    @PostMapping("/redis")
    public String dd(){
        redisUtil.set("token","111111111111111111111111111");
       return (String)redisUtil.get("token");
    }


    @GetMapping("test/user")
    public void testUser(){
        redisUtil.set("123", JsonUtils.objectToJson(userMapper.getDingTalkId("011055595258-1056822499")));
    }
}
